//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
class LoadingUI extends egret.Sprite {

    public constructor() {
        super();
        this.createView();
    }

    private textField: egret.TextField;
    private bmp: egret.Bitmap;
    private sp: egret.Sprite;
    private sp2: egret.Sprite;
    private bmp_bg0: egret.Bitmap;
    private bmp_bg1: egret.Bitmap;
    private bmp_build0: egret.Bitmap;
    private bmp_build1: egret.Bitmap;
    private bmp_build2: egret.Bitmap;
    private bmp_build3: egret.Bitmap;
    private bmp_build4: egret.Bitmap;

    private bmp_cloud0: egret.Bitmap;
    private bmp_cloud1: egret.Bitmap;
    private bmp_cloud2: egret.Bitmap;
    private bmp_cloud3: egret.Bitmap;
    private bmp_cloud4: egret.Bitmap;
    private bmp_cloud5: egret.Bitmap;

    private bmp_click: egret.Bitmap;

    private sc_bg: egret.SoundChannel;
    private sd_bg: egret.Sound;
    private sc_pos: number = 0;
    private bmp_test: egret.Bitmap;
    private msg: Mediator = Mediator.getInstance();

    private data;
    private txtr;
    private mcFactory: egret.MovieClipDataFactory;
    private mc_test: egret.MovieClip;

    private deltaBeta: number = 0;
    private deltaGamma: number = 0;
    private startBeta: number = 999;
    private startGamma: number = 999;
    private startX;
    private startY;
    private ob={};

    private sp_build: egret.Sprite = new egret.Sprite();
   
   //发光
   private mask0:egret.Shape;
   private mask1:egret.Shape;
   private bmp_glow0:egret.Bitmap=new egret.Bitmap();
   private bmp_glow1:egret.Bitmap=new egret.Bitmap();
   private sp_glow0Whole:egret.Sprite=new egret.Sprite();
   private sp_glow1Whole:egret.Sprite=new egret.Sprite();

    private video;
    private createView(): void {

        //    this.data = RES.getRes("testNew_json");
        //    this.txtr = RES.getRes("testNew_png");
        //    this.mcFactory = new egret.MovieClipDataFactory( this.data, this.txtr );
        //    this.mc_test=new egret.MovieClip(this.mcFactory.generateMovieClipData( "bbb" ));
        //    console.log(this.mc_test);
        //    this.addChild(this.mc_test);
        //    this.mc_test.gotoAndPlay(1);
        this.video = new egret.Video();
        this.video.x = 0;                       //设置视频坐标x
        this.video.y = 0;                       //设置视频坐标y
        this.video.width = 640;                 //设置视频宽
        this.video.height = 1136;                //设置视频高
        this.video.fullscreen = true;          //设置是否全屏（暂不支持移动设备）
        this.video.load("resource/assets/test.mp4");
        this.addChild(this.video);              //将视频添加到舞台

		//监听视频加载完成
        this.video.once(egret.Event.COMPLETE,this.onLoad,this);
        //监听视频加载失败
        this.video.once(egret.IOErrorEvent.IO_ERROR,this.onLoadErr,this);

        this.bmp_bg0 = new egret.Bitmap();
        this.bmp_bg0.texture = RES.getRes('bg0_png');
        this.ob['bg0X']=this.bmp_bg0.x=0;
        this.ob['bg0Y']=this.bmp_bg0.y=0;
        this.addChild(this.bmp_bg0);

        this.bmp_bg1 = new egret.Bitmap();
        this.bmp_bg1.texture = RES.getRes('bg1_png');
        // this.bmp_bg1.anchorOffsetX=this.bmp_bg1.width/2;
        // this.bmp_bg1.anchorOffsetY=this.bmp_bg1.height/2;
        this.ob['bg1X']=this.bmp_bg1.x=-30;
        this.ob['bg1Y']=this.bmp_bg1.y=0;
        this.addChild(this.bmp_bg1);
        
        this.bmp_cloud3 = new egret.Bitmap();
        this.bmp_cloud3.texture = RES.getRes('cloud0_png');
        this.bmp_cloud3.width=446;
        this.bmp_cloud3.height=247;
        this.ob['cloud3X']=this.bmp_cloud3.x=749;
        this.ob['cloud3Y']=this.bmp_cloud3.y=-123;
        this.bmp_cloud3.alpha=0.3;
        this.addChild(this.bmp_cloud3);
        egret.Tween.get(this.bmp_cloud3, { loop: true }).to({ scaleX: 1.01,scaleY: 1.01 }, 1500, egret.Ease.cubicInOut).to({scaleX: 1,scaleY:1 }, 1500, egret.Ease.cubicInOut);
        var sp_cloud3=new egret.Sprite();
        sp_cloud3.addChild(this.bmp_cloud3);
        egret.Tween.get(sp_cloud3, { loop: true }).to({ x:-50 }, 3000, egret.Ease.cubicInOut).to({x:0 }, 3000, egret.Ease.cubicInOut);
        this.addChild(sp_cloud3);

        this.bmp_build0 = new egret.Bitmap();
        this.bmp_build0.texture = RES.getRes('build0_png');
        this.ob['build0X']=this.bmp_build0.x=70;
        this.ob['build0Y']=this.bmp_build0.y=136;
        this.bmp_build0.alpha=1;
        this.addChild(this.bmp_build0);

        this.mask0=new egret.Shape();
        this.mask0.graphics.beginFill(0xff0000,1)
        this.mask0.graphics.drawRect(0,0,33,604);
        this.ob['mask0X']=this.mask0.x=280;
        this.ob['mask0Y']=this.mask0.y=70;
        this.mask0.alpha=0.5;
        this.addChild(this.mask0);
        this.bmp_glow0 = new egret.Bitmap();
        this.bmp_glow0.mask=new egret.Shape()
        this.bmp_glow0.texture = RES.getRes('glow0_png');
        this.ob['glow0X']=this.bmp_glow0.x=270;
        this.ob['glow0Y']=this.bmp_glow0.y=-43;
        this.bmp_glow0.alpha=1;
        // this.addChild(this.bmp_glow0);
        var sp_glow0:egret.Sprite=new egret.Sprite();
        sp_glow0.addChild(this.bmp_glow0);
        this.addChild(sp_glow0);
        sp_glow0.mask=this.mask0;
        sp_glow0.y=-170;
        egret.Tween.get(sp_glow0, { loop: true }).wait(0).to({ y:600 }, 7000, egret.Ease.cubicInOut);

        this.mask1=new egret.Shape();
        this.mask1.graphics.beginFill(0xff0000,1)
        this.mask1.graphics.drawRect(0,0,33,604);
        this.ob['mask1X']=this.mask1.x=280-221;
        this.ob['mask1Y']=this.mask1.y=70+70;
        this.mask1.alpha=0.5;
        this.addChild(this.mask1);
        this.bmp_glow1 = new egret.Bitmap();
        this.bmp_glow1.mask=new egret.Shape()
        this.bmp_glow1.texture = RES.getRes('glow0_png');
        this.ob['glow1X']=this.bmp_glow1.x=270-224;
        this.ob['glow1Y']=this.bmp_glow1.y=-43;
        this.bmp_glow1.alpha=1;
        // this.addChild(this.bmp_glow0);
        var sp_glow1:egret.Sprite=new egret.Sprite();
        sp_glow1.addChild(this.bmp_glow1);
        this.addChild(sp_glow1);
        sp_glow1.mask=this.mask1;
        sp_glow1.y=-150;
        egret.Tween.get(sp_glow1, { loop: true }).wait(1000).to({ y:600 }, 6000, egret.Ease.cubicInOut);

        this.bmp_build1 = new egret.Bitmap();
        this.bmp_build1.texture = RES.getRes('build1_png');
        this.ob['build1X']=this.bmp_build1.x=751;
        this.ob['build1Y']=this.bmp_build1.y=217;
        this.bmp_build1.alpha=1;
        this.addChild(this.bmp_build1);

        this.bmp_build2 = new egret.Bitmap();
        this.bmp_build2.texture = RES.getRes('build2_png');
        this.ob['build2X']=this.bmp_build2.x=850;
        this.ob['build2Y']=this.bmp_build2.y=30;
        this.bmp_build2.alpha=1;
        this.addChild(this.bmp_build2);

        this.bmp_build3 = new egret.Bitmap();
        this.bmp_build3.texture = RES.getRes('build3_png');
        this.ob['build3X']=this.bmp_build3.x=936;
        this.ob['build3Y']=this.bmp_build3.y=198;
        this.bmp_build1.alpha=1;
        this.addChild(this.bmp_build3);

        this.bmp_cloud5 = new egret.Bitmap();
        this.bmp_cloud5.texture = RES.getRes('cloud0_png');
        this.bmp_cloud5.width=225;
        this.bmp_cloud5.height=119;
        this.ob['cloud5X']=this.bmp_cloud5.x=910;
        this.ob['cloud5Y']=this.bmp_cloud5.y=200;
        this.bmp_cloud5.alpha=0.9;
        this.addChild(this.bmp_cloud5);
        egret.Tween.get(this.bmp_cloud5, { loop: true }).to({ scaleX: 1.02,scaleY: 1.02 }, 1200, egret.Ease.cubicInOut).to({scaleX: 1,scaleY:1 }, 1200, egret.Ease.cubicInOut);
        var sp_cloud5=new egret.Sprite();
        sp_cloud5.addChild(this.bmp_cloud5);
        egret.Tween.get(sp_cloud5, { loop: true }).to({ x:40 }, 2900, egret.Ease.cubicInOut).to({x:0 }, 2900, egret.Ease.cubicInOut);
        this.addChild(sp_cloud5);  

        this.bmp_build4 = new egret.Bitmap();
        this.bmp_build4.texture = RES.getRes('build4_png');
        this.ob['build4X']=this.bmp_build4.x=1026;
        this.ob['build4Y']=this.bmp_build4.y=147;
        this.bmp_build4.alpha=1;
        this.addChild(this.bmp_build4);

        this.bmp_cloud0 = new egret.Bitmap();
        this.bmp_cloud0.texture = RES.getRes('cloud0_png');
        this.bmp_cloud0.width=289;
        this.bmp_cloud0.height=153;
        this.ob['cloud0X']=this.bmp_cloud0.x=-100;
        this.ob['cloud0Y']=this.bmp_cloud0.y=64;
        this.bmp_cloud0.alpha=1;
        this.addChild(this.bmp_cloud0);
        egret.Tween.get(this.bmp_cloud0, { loop: true }).to({ scaleX: 1.02,scaleY: 1.02 }, 1000, egret.Ease.cubicInOut).to({scaleX: 1,scaleY:1 }, 1000, egret.Ease.cubicInOut);
        var sp_cloud0=new egret.Sprite();
        sp_cloud0.addChild(this.bmp_cloud0);
        egret.Tween.get(sp_cloud0, { loop: true }).to({ x:-45 }, 3100, egret.Ease.cubicInOut).to({x:0 }, 3100, egret.Ease.cubicInOut);
        this.addChild(sp_cloud0); 
                
        this.bmp_cloud2 = new egret.Bitmap();
        this.bmp_cloud2.texture = RES.getRes('cloud0_png');
        this.bmp_cloud2.width=186;
        this.bmp_cloud2.height=78;
        this.ob['cloud2X']=this.bmp_cloud2.x=651;
        this.ob['cloud2Y']=this.bmp_cloud2.y=185;
        this.bmp_cloud2.alpha=0.7;
        this.addChild(this.bmp_cloud2);
        egret.Tween.get(this.bmp_cloud2, { loop: true }).to({ scaleX: 1.02,scaleY: 1.02 }, 900, egret.Ease.cubicInOut).to({ scaleX: 1,scaleY:1 }, 900, egret.Ease.cubicInOut);  
        var sp_cloud2=new egret.Sprite();
        sp_cloud2.addChild(this.bmp_cloud2);
        egret.Tween.get(sp_cloud2, { loop: true }).to({ x:-50 }, 2700, egret.Ease.cubicInOut).to({x:0 }, 2700, egret.Ease.cubicInOut);
        this.addChild(sp_cloud2);      

        this.bmp_cloud4 = new egret.Bitmap();
        this.bmp_cloud4.texture = RES.getRes('cloud0_png');
        this.bmp_cloud4.width=82;
        this.bmp_cloud4.height=43;
        this.ob['cloud4X']=this.bmp_cloud4.x=811;
        this.ob['cloud4Y']=this.bmp_cloud4.y=282;
        this.bmp_cloud4.alpha=1;
        this.addChild(this.bmp_cloud4);
        egret.Tween.get(this.bmp_cloud4, { loop: true }).to({ scaleX: 1.03,scaleY: 1.03 }, 700, egret.Ease.cubicInOut).to({scaleX: 1,scaleY:1 }, 700, egret.Ease.cubicInOut);
        var sp_cloud4=new egret.Sprite();
        sp_cloud4.addChild(this.bmp_cloud4);
        egret.Tween.get(sp_cloud4, { loop: true }).to({ x:25 }, 3100, egret.Ease.cubicInOut).to({x:0 }, 3100, egret.Ease.cubicInOut);
        this.addChild(sp_cloud4);     

        this.bmp_cloud1 = new egret.Bitmap();
        this.bmp_cloud1.texture = RES.getRes('cloud1_png');
        this.bmp_cloud1.width=289;
        this.bmp_cloud1.height=153;
        this.ob['cloud1X']=this.bmp_cloud1.x=140;
        this.ob['cloud1Y']=this.bmp_cloud1.y=400;
        this.bmp_cloud1.alpha=1;
        this.addChild(this.bmp_cloud1);
        egret.Tween.get(this.bmp_cloud1, { loop: true }).to({  scaleX: 1.02,scaleY: 1.02 }, 1500, egret.Ease.cubicInOut).to({ scaleX: 1,scaleY:1 }, 1500, egret.Ease.cubicInOut);
        var sp_cloud1=new egret.Sprite();
        sp_cloud1.addChild(this.bmp_cloud1);
        egret.Tween.get(sp_cloud1, { loop: true }).to({ x:50 }, 2500, egret.Ease.cubicInOut).to({x:0 }, 2500, egret.Ease.cubicInOut);
        this.addChild(sp_cloud1);    

        

        //    this.bmp_test=new egret.Bitmap();
        //    this.bmp_test.texture=RES.getRes('test_png');
        //    this.bmp_test.anchorOffsetX=this.bmp_test.width/2;
        //    this.bmp_test.anchorOffsetY=this.bmp_test.height/2;
        //    this.addChild(this.bmp_test);
        //    this.startX=this.bmp_test.x=1136/2;
        //    this.startY=this.bmp_test.y=640/2;


        this.bmp = new egret.Bitmap();
        this.bmp.texture = RES.getRes('创邑_LOGO_png');
        this.bmp.name = 'l';
        this.bmp.anchorOffsetX=this.bmp.width/2;
        this.bmp.anchorOffsetY=this.bmp.height/2;

        this.bmp.x = 560;
        this.bmp.y = 333;
        this.addChild(this.bmp);
        egret.Tween.get(this.bmp, { loop: true }).to({ alpha: 1, scaleX: 1.05,scaleY: 1.05 }, 500, egret.Ease.cubicInOut).to({ alpha: 1, scaleX: 1,scaleY:1 }, 500, egret.Ease.cubicInOut);

        this.bmp_click= new egret.Bitmap();
        this.bmp_click.texture = RES.getRes('click_png');
        this.bmp_click.anchorOffsetX=this.bmp_click.width/2;
        this.bmp_click.anchorOffsetY=this.bmp_click.height/2;
        this.bmp_click.x = 533;
        this.bmp_click.y = 343;
        this.bmp_click.touchEnabled=true;
        this.bmp_click.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchHandler,this);

        this.textField = new egret.TextField();
        // this.addChild(this.textField);
        this.textField.x = 370;
        this.textField.y = 942;
        this.textField.width = 480;
        this.textField.height = 100;
        this.textField.textColor = 0xEF7C1B;
        this.textField.anchorOffsetX = this.textField.width / 2;
        this.textField.anchorOffsetY = this.textField.height / 2;
        this.textField.size = 90;
        this.textField.textAlign = "center";

        this.sp = new egret.Sprite();
        this.sp.graphics.beginFill(0xcccccc, 1);
        this.sp.graphics.drawRect(0, 0, 500, 4);
        this.sp.anchorOffsetY = this.sp.height / 2;
        this.sp.x = (1136 - this.sp.width) / 2;
        this.sp.y = 640 / 2 + 50;

        this.sp2 = new egret.Sprite();
        this.sp2.graphics.beginFill(0xffffff, 1);
        this.sp2.graphics.drawRect(0, 0, 450, 4);
        this.sp2.anchorOffsetX = 0;
        this.sp2.anchorOffsetY = this.sp2.height / 2;
        this.sp2.x = (1136 - this.sp2.width) / 2;
        this.sp2.y = 640 / 2 + 50;
        this.sp2.scaleX = 0;

        // this.addChild(this.sp);
        // this.addChild(this.sp2);

        this.msg.addEventListener('PhoneAction_Orient', this.msgHandler, this);
        this.addEventListener(egret.Event.ENTER_FRAME, this.round, this);
    }
    private lastGamma;
    private msgHandler(e: MediatorEvent): void {
        // if(this.lastGamma*e.data[2]<0)
        // {
        //     return;
        // }
        if (this.startBeta == 999) {
            this.startBeta = e.data[1];
            this.lastGamma=this.startGamma = e.data[2];
        }
        this.deltaGamma = e.data[2] - this.startGamma;
        this.deltaBeta = e.data[1] - this.startBeta;
    }
    private round(e: egret.Event): void {

        // this.bmp_test.x+=(this.startX+this.deltaBeta-this.bmp_test.x)*0.4;
        // this.bmp_test.y+=(this.startY+this.deltaGamma-this.bmp_test.y)*0.4;
        this.bmp_bg1.x+=(this.ob['bg1X']+this.deltaBeta*1.2-this.bmp_bg1.x)*0.4;
        this.bmp_bg1.y+=(this.ob['bg1Y']-this.deltaGamma*1-this.bmp_bg1.y)*0.4;
        
        if(this.bmp_bg1.x>this.ob['bg1X']+30)
        {
            this.bmp_bg1.x=this.ob['bg1X']+30;
        }
        else if(this.bmp_bg1.x<this.ob['bg1X']-30)
        {
            this.bmp_bg1.x=this.ob['bg1X']-30;
        }
        if(this.bmp_bg1.y<this.ob['bg1Y']-30)
        {
            this.bmp_bg1.y=this.ob['bg1Y']-30;
        }
        else if(this.bmp_bg1.y>this.ob['bg1Y']+30)
        {
            this.bmp_bg1.y=this.ob['bg1Y']+30;
        }

        this.mask0.x+=(this.ob['mask0X']-this.deltaBeta*2-this.mask0.x)*0.4;
        this.mask0.y+=(this.ob['mask0Y']-this.deltaGamma*1.5-this.mask0.y)*0.4;
        if(this.mask0.x>this.ob['mask0X']+10)
        {
            this.mask0.x=this.ob['mask0X']+10;
        }
        if(this.mask0.x<this.ob['mask0X']-90)
        {
            this.mask0.x=this.ob['mask0X']-90;
        }
        if(this.mask0.y>this.ob['mask0Y']+90)
        {
            this.mask0.y=this.ob['mask0Y']+90;
        }
        else if(this.mask0.y<this.ob['mask0Y']-90)
        {
            this.mask0.y=this.ob['mask0Y']-90;
        }

        this.mask1.x+=(this.ob['mask1X']-this.deltaBeta*2-this.mask1.x)*0.4;
        this.mask1.y+=(this.ob['mask1Y']-this.deltaGamma*1.5-this.mask1.y)*0.4;
        if(this.mask1.x>this.ob['mask1X']+10)
        {
            this.mask1.x=this.ob['mask1X']+10;
        }
        if(this.mask1.x<this.ob['mask1X']-90)
        {
            this.mask1.x=this.ob['mask1X']-90;
        }
        if(this.mask1.y>this.ob['mask1Y']+90)
        {
            this.mask1.y=this.ob['mask1Y']+90;
        }
        else if(this.mask1.y<this.ob['mask1Y']-90)
        {
            this.mask1.y=this.ob['mask1Y']-90;
        }

        this.bmp_glow0.x+=(this.ob['glow0X']-this.deltaBeta*2-this.bmp_glow0.x)*0.4;
        this.bmp_glow0.y+=(this.ob['glow0X']-this.deltaGamma*1.5-this.bmp_glow0.y)*0.4;
        if(this.bmp_glow0.x>this.ob['glow0X']+10)
        {
            this.bmp_glow0.x=this.ob['glow0X']+10;
        }
        if(this.bmp_glow0.x<this.ob['glow0X']-90)
        {
            this.bmp_glow0.x=this.ob['glow0X']-90;
        }
        if(this.bmp_glow0.y>this.ob['glow0Y']+90)
        {
            this.bmp_glow0.y=this.ob['glow0Y']+90;
        }
        else if(this.bmp_glow0.y<this.ob['glow0Y']-90)
        {
            this.bmp_glow0.y=this.ob['glow0Y']-90;
        }

        this.bmp_glow1.x+=(this.ob['glow1X']-this.deltaBeta*2-this.bmp_glow1.x)*0.4;
        this.bmp_glow1.y+=(this.ob['glow1X']-this.deltaGamma*1.5-this.bmp_glow1.y)*0.4;
        if(this.bmp_glow1.x>this.ob['glow1X']+10)
        {
            this.bmp_glow1.x=this.ob['glow1X']+10;
        }
        if(this.bmp_glow1.x<this.ob['glow1X']-90)
        {
            this.bmp_glow1.x=this.ob['glow1X']-90;
        }
        if(this.bmp_glow1.y>this.ob['glow1Y']+90)
        {
            this.bmp_glow1.y=this.ob['glow1Y']+90;
        }
        else if(this.bmp_glow1.y<this.ob['glow1Y']-90)
        {
            this.bmp_glow1.y=this.ob['glow1Y']-90;
        }

        this.bmp_build0.x+=(this.ob['build0X']-this.deltaBeta*2-this.bmp_build0.x)*0.4;
        this.bmp_build0.y+=(this.ob['build0X']-this.deltaGamma*1.5-this.bmp_build0.y)*0.4;
        if(this.bmp_build0.x>this.ob['build0X']+10)
        {
            this.bmp_build0.x=this.ob['build0X']+10;
        }
        if(this.bmp_build0.x<this.ob['build0X']-90)
        {
            this.bmp_build0.x=this.ob['build0X']-90;
        }
        if(this.bmp_build0.y>this.ob['build0Y']+90)
        {
            this.bmp_build0.y=this.ob['build0Y']+90;
        }
        else if(this.bmp_build0.y<this.ob['build0Y']-90)
        {
            this.bmp_build0.y=this.ob['build0Y']-90;
        }

        this.bmp_build1.x+=(this.ob['build1X']+this.deltaBeta*1.5-this.bmp_build1.x)*0.4;
        this.bmp_build1.y+=(this.ob['build1Y']-this.deltaGamma*1-this.bmp_build1.y)*0.4;
        if(this.bmp_build1.x>this.ob['build1X']+50)
        {
            this.bmp_build1.x=this.ob['build1X']+50;
        }
        else if(this.bmp_build1.x<this.ob['build1X']-50)
        {
            this.bmp_build1.x=this.ob['build1X']-50;
        }
        if(this.bmp_build1.y>this.ob['build1Y']+40)
        {
            this.bmp_build1.y=this.ob['build1Y']+40;
        }
        else if(this.bmp_build1.y<this.ob['build1Y']-40)
        {
            this.bmp_build1.y=this.ob['build1Y']-40;
        }

        this.bmp_build2.x+=(this.ob['build2X']+this.deltaBeta*2.1-this.bmp_build2.x)*0.4;
        this.bmp_build2.y+=(this.ob['build2Y']-this.deltaGamma*1.2-this.bmp_build2.y)*0.4;
         if(this.bmp_build2.x>this.ob['build2X']+100)
        {
            this.bmp_build2.x=this.ob['build2X']+100;
        }
        else if(this.bmp_build2.x<this.ob['build2X']-40)
        {
            this.bmp_build2.x=this.ob['build2X']-40;
        }
        if(this.bmp_build2.y>this.ob['build2Y']+30)
        {
            this.bmp_build2.y=this.ob['build2Y']+30;
        }
        else if(this.bmp_build2.y<this.ob['build2Y']-70)
        {
            this.bmp_build2.y=this.ob['build2Y']-70;
        }

        this.bmp_build3.x+=(this.ob['build3X']+this.deltaBeta*2.4-this.bmp_build3.x)*0.4;
        this.bmp_build3.y+=(this.ob['build3Y']-this.deltaGamma*1.1-this.bmp_build3.y)*0.4;
         if(this.bmp_build3.x>this.ob['build3X']+100)
        {
            this.bmp_build3.x=this.ob['build3X']+100;
        }
        else if(this.bmp_build3.x<this.ob['build3X']-50)
        {
            this.bmp_build3.x=this.ob['build3X']-50;
        }
        if(this.bmp_build3.y>this.ob['build3Y']+30)
        {
            this.bmp_build3.y=this.ob['build3Y']+30;
        }
        else if(this.bmp_build3.y<this.ob['build3Y']-70)
        {
            this.bmp_build3.y=this.ob['build3Y']-70;
        }

        this.bmp_build4.x+=(this.ob['build4X']+this.deltaBeta*1.9-this.bmp_build4.x)*0.4;
        this.bmp_build4.y+=(this.ob['build4Y']-this.deltaGamma*1-this.bmp_build4.y)*0.4;
         if(this.bmp_build4.x>this.ob['build4X']+70)
        {
            this.bmp_build4.x=this.ob['build4X']+70;
        }
        else if(this.bmp_build4.x<this.ob['build4X']-40)
        {
            this.bmp_build4.x=this.ob['build4X']-40;
        }
        if(this.bmp_build4.y>this.ob['build4Y']+30)
        {
            this.bmp_build4.y=this.ob['build4Y']+30;
        }
        else if(this.bmp_build4.y<this.ob['build4Y']-70)
        {
            this.bmp_build4.y=this.ob['build4Y']-70;
        }

        this.bmp_cloud0.x+=(this.ob['cloud0X']+this.deltaBeta*1.2-this.bmp_cloud0.x)*0.4;
        this.bmp_cloud0.y+=(this.ob['cloud0Y']-this.deltaGamma*1.2-this.bmp_cloud0.y)*0.4;
         if(this.bmp_cloud0.x>this.ob['cloud0X']+45)
        {
            this.bmp_cloud0.x=this.ob['cloud0X']+45;
        }
        else if(this.bmp_cloud0.x<this.ob['cloud0X']-45)
        {
            this.bmp_cloud0.x=this.ob['cloud0X']-45;
        }
        if(this.bmp_cloud0.y>this.ob['cloud0Y']+35)
        {
            this.bmp_cloud0.y=this.ob['cloud0Y']+35;
        }
        else if(this.bmp_cloud0.y<this.ob['cloud0Y']-35)
        {
            this.bmp_cloud0.y=this.ob['cloud0Y']-35;
        }

        this.bmp_cloud1.x+=(this.ob['cloud1X']+this.deltaBeta*1.3-this.bmp_cloud1.x)*0.4;
        this.bmp_cloud1.y+=(this.ob['cloud1Y']-this.deltaGamma*1.3-this.bmp_cloud1.y)*0.4;
         if(this.bmp_cloud1.x>this.ob['cloud1X']+50)
        {
            this.bmp_cloud1.x=this.ob['cloud1X']+50;
        }
        else if(this.bmp_cloud1.x<this.ob['cloud1X']-50)
        {
            this.bmp_cloud1.x=this.ob['cloud1X']-50;
        }
        if(this.bmp_cloud1.y>this.ob['cloud1Y']+40)
        {
            this.bmp_cloud1.y=this.ob['cloud1Y']+40;
        }
        else if(this.bmp_cloud1.y<this.ob['cloud1Y']-40)
        {
            this.bmp_cloud1.y=this.ob['cloud1Y']-40;
        }

        this.bmp_cloud2.x+=(this.ob['cloud2X']+this.deltaBeta*1.2-this.bmp_cloud2.x)*0.4;
        this.bmp_cloud2.y+=(this.ob['cloud2Y']-this.deltaGamma*1.2-this.bmp_cloud2.y)*0.4;
         if(this.bmp_cloud2.x>this.ob['cloud2X']+35)
        {
            this.bmp_cloud2.x=this.ob['cloud2X']+35;
        }
        else if(this.bmp_cloud2.x<this.ob['cloud2X']-35)
        {
            this.bmp_cloud2.x=this.ob['cloud2X']-35;
        }
        if(this.bmp_cloud2.y>this.ob['cloud2Y']+35)
        {
            this.bmp_cloud2.y=this.ob['cloud2Y']+35;
        }
        else if(this.bmp_cloud2.y<this.ob['cloud2Y']-35)
        {
            this.bmp_cloud2.y=this.ob['cloud2Y']-35;
        }

        this.bmp_cloud3.x+=(this.ob['cloud3X']+this.deltaBeta*1.2-this.bmp_cloud3.x)*0.4;
        this.bmp_cloud3.y+=(this.ob['cloud3Y']-this.deltaGamma*1.2-this.bmp_cloud3.y)*0.4;
         if(this.bmp_cloud3.x>this.ob['cloud3X']+35)
        {
            this.bmp_cloud3.x=this.ob['cloud3X']+35;
        }
        else if(this.bmp_cloud3.x<this.ob['cloud3X']-35)
        {
            this.bmp_cloud3.x=this.ob['cloud3X']-35;
        }
        if(this.bmp_cloud3.y>this.ob['cloud3Y']+35)
        {
            this.bmp_cloud3.y=this.ob['cloud3Y']+35;
        }
        else if(this.bmp_cloud3.y<this.ob['cloud3Y']-35)
        {
            this.bmp_cloud3.y=this.ob['cloud3Y']-35;
        }

        this.bmp_cloud4.x+=(this.ob['cloud4X']+this.deltaBeta*1.1-this.bmp_cloud4.x)*0.4;
        this.bmp_cloud4.y+=(this.ob['cloud4Y']-this.deltaGamma*1.1-this.bmp_cloud4.y)*0.4;
         if(this.bmp_cloud4.x>this.ob['cloud4X']+40)
        {
            this.bmp_cloud4.x=this.ob['cloud4X']+40;
        }
        else if(this.bmp_cloud4.x<this.ob['cloud4X']-40)
        {
            this.bmp_cloud4.x=this.ob['cloud4X']-40;
        }
        if(this.bmp_cloud4.y>this.ob['cloud4Y']+40)
        {
            this.bmp_cloud4.y=this.ob['cloud4Y']+40;
        }
        else if(this.bmp_cloud4.y<this.ob['cloud4Y']-40)
        {
            this.bmp_cloud4.y=this.ob['cloud4Y']-40;
        }

        this.bmp_cloud5.x+=(this.ob['cloud5X']+this.deltaBeta*1.3-this.bmp_cloud5.x)*0.4;
        this.bmp_cloud5.y+=(this.ob['cloud5Y']-this.deltaGamma*1.3-this.bmp_cloud5.y)*0.4;
         if(this.bmp_cloud5.x>this.ob['cloud5X']+45)
        {
            this.bmp_cloud5.x=this.ob['cloud5X']+45;
        }
        else if(this.bmp_cloud5.x<this.ob['cloud5X']-45)
        {
            this.bmp_cloud5.x=this.ob['cloud5X']-45;
        }
        if(this.bmp_cloud5.y>this.ob['cloud5Y']+45)
        {
            this.bmp_cloud5.y=this.ob['cloud5Y']+45;
        }
        else if(this.bmp_cloud5.y<this.ob['cloud5Y']-45)
        {
            this.bmp_cloud5.y=this.ob['cloud5Y']-45;
        }
    }


    public setProgress(current: number, total: number): void {
        console.log(current, total);
        // this.textField.text = `Loading...${current}/${total}`;
        // this.textField.text=String(Math.floor(100*current/total));
        this.sp2.scaleX = current / total;
        var myThis = this;
        if (current / total == 1) {
            egret.Tween.get(this.bmp).pause();
            egret.Tween.pauseTweens(this.bmp);
            egret.Tween.get(this.bmp).to({ alpha: 0, y: -700 }, 1000, egret.Ease.backIn);
            egret.Tween.get(this.sp2).wait(0).to({ alpha: 0,y:700 }, 1000, egret.Ease.backIn);
            
            this.addChild(this.bmp_click);
            this.bmp_click.alpha=0;
            this.bmp_click.y=343+300;
            egret.Tween.get(this.bmp_click).wait(1000).to({ alpha: 1, y: 333 }, 1000, egret.Ease.backOut);
            egret.Tween.get(this.bmp_click, { loop: true }).to({scaleX: 1.05,scaleY: 1.05 }, 500, egret.Ease.cubicInOut).to({scaleX: 1,scaleY:1 }, 500, egret.Ease.cubicInOut);
        }
    }

    private touchHandler(e:egret.TouchEvent):void
    {
        console.log(e.type);
        if(e.type=='touchBegin')
        {
            if(this.bool_loaded)
            {
                this.video.play();
            }
            // this.msg.dispatchEvent(new MediatorEvent('Main_GameIn'));
        }
    }

    public playMusic(): void {
        this.sc_bg = this.sd_bg.play(this.sc_pos, 0);
    }
    public stopMusic(): void {
        if (this.sc_bg) {
            console.log('stop!!');
            this.sc_pos = this.sc_bg.position;
            this.sc_bg.stop();
            this.sc_bg = null;
        }
    }
    private bool_loaded;
    private onLoad(e: egret.Event) {
		// this.msg.dispatchEvent(new MediatorEvent('VideoLoaded'));
		// this.video.play();
        this.bool_loaded=true;
    }
    private onLoadErr(e: egret.Event) {
        console.log("video load error happened");
    }
}
